<?php

namespace App\Controller;

class Request
{
    private static $_instance;

    protected $_serverMap = array(
        'method'    => 'REQUEST_METHOD',
        'uri'       => 'REQUEST_URI',
        'client_ip' => 'REMOTE_ADDR',
        'timestamp' => 'REQUEST_TIME',
        'argv'      => 'argv',
        'qs'        => 'QUERY_STRING',
        'ua'        => 'HTTP_USER_AGENT',
        'referer'   => 'HTTP_REFERER',
        'pathinfo'  => 'PATH_INFO'
    );

    public function __construct()
    {

    }

    public function __get($name)
    {
        if (isset($this->_serverMap[$name]) && isset($_SERVER[$this->_serverMap[$name]]))
        {
            return $_SERVER[$this->_serverMap[$name]];
        }

        return '';
    }

    public function __isset($name)
    {
        return isset($this->_serverMap[$name]);
    }

    public static function getInstance()
    {
        if (self::$_instance instanceof Request)
        {
            self::$_instance = new self();
        }

        return self::$_instance;
    }

    public function getPathInfo()
    {
        return isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : strtr($_SERVER['REQUEST_URI'], array('index.php' => ''));
    }

    public function setParams()
    {

    }

    public function isGET()
    {
        return 'GET' === $_SERVER['REQUEST_METHOD'];
    }

    public function isPOST()
    {
        return 'POST' === $_SERVER['REQUEST_METHOD'];
    }

    public function isAjax()
    {

    }
}